﻿using System;

namespace UniRx.Operators
{
	// Token: 0x0200027B RID: 635
	internal class CreateObservable<T> : OperatorObservableBase<T>
	{
		// Token: 0x06000E4F RID: 3663 RVA: 0x00043840 File Offset: 0x00041C40
		public CreateObservable(Func<IObserver<T>, IDisposable> subscribe) : base(true)
		{
			this.subscribe = subscribe;
		}

		// Token: 0x06000E50 RID: 3664 RVA: 0x00043850 File Offset: 0x00041C50
		public CreateObservable(Func<IObserver<T>, IDisposable> subscribe, bool isRequiredSubscribeOnCurrentThread) : base(isRequiredSubscribeOnCurrentThread)
		{
			this.subscribe = subscribe;
		}

		// Token: 0x06000E51 RID: 3665 RVA: 0x00043860 File Offset: 0x00041C60
		protected override IDisposable SubscribeCore(IObserver<T> observer, IDisposable cancel)
		{
			observer = new CreateObservable<T>.Create(observer, cancel);
			return this.subscribe(observer) ?? Disposable.Empty;
		}

		// Token: 0x04000849 RID: 2121
		private readonly Func<IObserver<T>, IDisposable> subscribe;

		// Token: 0x0200027C RID: 636
		private class Create : OperatorObserverBase<T, T>
		{
			// Token: 0x06000E52 RID: 3666 RVA: 0x00043883 File Offset: 0x00041C83
			public Create(IObserver<T> observer, IDisposable cancel) : base(observer, cancel)
			{
			}

			// Token: 0x06000E53 RID: 3667 RVA: 0x0004388D File Offset: 0x00041C8D
			public override void OnNext(T value)
			{
				this.observer.OnNext(value);
			}

			// Token: 0x06000E54 RID: 3668 RVA: 0x000438A0 File Offset: 0x00041CA0
			public override void OnError(Exception error)
			{
				try
				{
					this.observer.OnError(error);
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x06000E55 RID: 3669 RVA: 0x000438D8 File Offset: 0x00041CD8
			public override void OnCompleted()
			{
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}
		}
	}
}
